<?php

class mullet
{
	var $mul_db;	// Mullet DB connection.
	var $smf_db;	// SMF DB connection.
	
	var $events =	array();





	// Constructor
	function mullet($mul_db, $smf_db)
	{
		$this->mul_db = $mul_db;
		$this->smf_db = $smf_db;
	}





	// Load events from database.
	function getEvents($low_bound, $up_bound = NULL)
	{
		global $mConfig;


		// Since we're populating the array, just clear out whatever is in there now.
		unset($this->events);
		$this->events = array();





		// If no upper boundry is set just get events starting from the lower boundry.
		if ($up_bound == NULL)
		{
			$sql_query = 'SELECT event_id FROM '.$mConfig['table_events'].' WHERE start_time > '.$low_bound.' ORDER BY start_time';
		}
		
		// Otherwise get all the events between the boundries.
		else
		{
			$sql_query =
				'SELECT event_id FROM '.$mConfig['table_events'].' WHERE start_time > '.$low_bound.'
				and WHERE start_time < '.$up_bound.' ORDER BY start_time';
		}

		$sql_result = mysql_query($sql_query, $this->mul_db) or die('There was an error querying events from Mullet.');





		// Create the array of event instances.
		while ($sql_fetch = mysql_fetch_assoc($sql_result))
		{
			$tempEvent = new event($this->mul_db, $this->smf_db, $sql_fetch['event_id']);
			
			$this->events[] = $tempEvent;
			
			unset($tempEvent);
		}
		
		unset($sql_query); mysql_free_result($sql_result); unset($sql_fetch);
	}





	// Load events from database.
	function getEventsByCreation($numevents = 0)
	{
		global $mConfig;



		$events = array();

                if ($numevents <= 0)
                    $numevents = 10;

		$sql_query = 'SELECT event_id FROM '.$mConfig['table_events'].' ORDER BY event_id desc limit '.$numevents;
		$sql_result = mysql_query($sql_query, $this->mul_db) or die('There was an error querying events from Mullet.');
		
		while ($sql_fetch = mysql_fetch_assoc($sql_result))
		{
			$events[] = $sql_fetch['event_id'];
		}

		unset($sql_query); mysql_free_result($sql_result); unset($sql_fetch);
		
		return $events;
	}

}
?>